<!DOCTYPE html>
<html lang="en">
<head>
	<title>填写改约单</title>
	<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, maximum-scale=1, user-scalable=no" charset="UTF-8">
	<link rel="stylesheet" href="android_asset://css/style.css"/>
    <link rel="stylesheet" href="android_asset://css/font.css"/>
</head>
<body>
	<div id="change_date">
		<form id="form" class="form-horizontal" style="position: relative;" action="/tickets/{{ticketId}}/">
			<input type="hidden" name="ticketid" value="{{ticketId}}"> 
			<div class="form-group clearfix">
				<div class="content">
			    	<label  class="left control-label">请求人</label>
			    	<div class="right">
			    		<p>{{ticketEx.customername}}</p>
			    	</div>
		    	</div>
		  	</div>
		  	<div class="form-group clearfix">
		  		<div class="content">
			    	<label  class="left control-label">联系电话</label>
			    	<div class="right">
			    	  {% if ticketEx.customermobile is not null %}
			    		<a href="javascript:;" class="form-control call" onclick="msAndroid.call('{{ticketEx.customermobile}}')">{{ticketEx.customermobile}}</a>
			    	  {% elseif ticketEx.customerphone is not null %}
			    	    <a href="javascript:;" onclick="msAndroid.call('{{ticketEx.customerphone}}')" class="form-control call">{{ticketEx.customerphone}}</a>
			    	  {% endif %}
			    	</div>
		    	</div>
		  	</div>
		  	{% if ticketEx.customerphone is not null and ticketEx.customermobile is not null %}
		  	<div class="form-group clearfix">
		  	    <div class="content">
			    	<label  class="left control-label"></label>
			    	<div class="right">
			    		<a href="javascript:;" onclick="msAndroid.call('{{ticketEx.customerphone}}')" class="form-control call">{{ticketEx.customerphone}}</a>
			    	</div>
		    	</div>
		  	</div>
            {% endif %}
		  	<div class="form-group clearfix">
		  		<div class="content content_table">
			    	<span class="table_title"><label  class="left control-label">羲和地址</label></span>
			    	<div class="right table_right">
				     	<p>{{ticketEx.customeraddress}}</p>
			    	</div>
			    </div>
		  	</div>
		  	
		  	<!-- 新增改约类型 -->
		 	<div class="form-group clearfix martop bortno">
		    	<div class="content">
			    	<label  class="left control-label">改约类型</label>
			   		<div class="right bug_right" style="width: 60%">
			   			<span class="icon-rightarrow right blick_icon"></span>
			    		<input type="text" id="appintType" onclick="appinttype(this)" class="form-control blick_input" readonly="readonly" placeholder="立即改约" value="立即改约">
			    	</div>
		    	</div>
		  	</div>
		 	<div id="changAppintType">
			 	<div class="form-group clearfix">
			  	    <div class="content">
				    	<label  class="left control-label">改约到场时间</label>
				   		<div class="right bug_right" style="width: 60%">
				   			<span class="icon-rightarrow right blick_icon"></span>
				    		<input type="text" required onclick="msAndroid.datePicker(this,'#pendingtime')" class="form-control blick_input" readonly="readonly"  placeholder="设定改约到场时间" value="">
				    		<input type="hidden" name="pendingtime" id="pendingtime">
				    	</div>
			    	</div>
			  	</div>
			  	<div class="form-group clearfix">
			  		<div class="content">
				    	<label  class="left control-label">事前提醒</label>
				    	<div class="right bug_right" style="width: 60%">
			   				<span class="icon-rightarrow right blick_icon"></span>
					     	<input type="text" id="timeRemindText" required class="form-control timeRemindText blick_input" readonly="readonly"  placeholder="设置提醒时间" onclick="timeremind(this,'#timeRemind')" >
					     	<input type="hidden" id="timeRemind" name="remindTime">
				    	</div>
			    	</div>
			  	</div>
			  	<div class="form-group clearfix">
			  	    <div class="content">
				    	<label  class="left control-label">上门地址</label>
				    	<div class="right address setUP">
				    		<span class="icon-rightarrow right"></span>
					     	<textarea name="address" required  id="location" class="form-control" readonly="readonly"  placeholder="设置上门地址" onclick="msAndroid.location('#location','#lat','#long')"></textarea> 
				    	    <input type="hidden" id="lat" name="latitude">
				    	    <input type="hidden" id="long" name="longitude">
				    	</div>
			    	</div>
			  	</div>
		 	</div>
		  	

		  	<div class="form-group leo">
		  	    <div class="content">
			    	<label class="control-label">改约原因</label>
			    	<div class="describe">
						<textarea id="pendingcause" name="pendingcause" placeholder="填写改约原因" required  cols="30" rows="5" style="width:100%"></textarea>
			    	</div>
		    	</div>
		  	</div>
		</form>
		<!--改约模式-->
		<div class="confirm">
			<button type="button" action="reappoint" class="btn"><a href="javascript:;">立即改约</a></button>
			
		</div>
	</div>
</body>
<script src="android_asset://jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="android_asset://jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="android_asset://bridge.js" type="text/javascript"></script>
<script src="android_asset://android.js" type="text/javascript"></script>
<script type="text/javascript">
//  页面缓存，-----到场时间-------事前提醒-----上门地址
var cacheHTML,pendingtime,timeRemindText,location_;
//改约类型切换
function appinttype(textPicker){
	if(msAndroid[textPicker]==null||msAndroid[textPicker]<0){
		msAndroid[textPicker]=0
	}
	var menu=[{text:"立即改约",value:"reappoint",index:0},
	          {text:"下次再约",value:"confirm",index:1},
	          {text:"取消",value:"取消",index:2}];
	msAndroid.menu(menu,function(response){
		var obj=eval('('+response+')');
		if(obj.status==1){
			if(obj.data.index==2){
				return;
			}
			$(textPicker).val(obj.data.text);
			msAndroid[textPicker]=obj.data.index;
			 $(".confirm button a").text(obj.data.text);
             $(".confirm button").attr("action",menu[obj.data.index].value);
			if(obj.data.index==1){//下次再约
				cacheHTML = $("#changAppintType").html();
				pendingtime = $("#pendingtime").val();
				timeRemindText = $("#timeRemind").val();
				location_ = $("#location").val();
				$("#changAppintType").html("");
			}else{//立即改约
				$("#changAppintType").html(cacheHTML);
				$("#pendingtime").val(pendingtime)
				$("#timeRemindText").val(timeRemindText)
				$("#location").val(location_)
			}
		}else{
			toast(obj.message);
		}
	},msAndroid[textPicker]);
}

$(function(){
	cacheHTML = $("#changAppintType").html();
	
	$(".confirm button").click(function(){
		if($("#appintType").val()=="立即改约"){
			//上门地址换行
			var elem=$("#location"); 
			if(elem.val().length>12){
				$(".setUP").css("line-height","2em");
				elem.css("padding-top",".7em");
			}else{
				$(".setUP").css("line-height","1em");
				elem.css("padding-top","1em");
			}
			
			if($("#pendingtime").val().length==0){
				msAndroid.toast("设定改约到场时间");
				return;
			}
			if($("#timeRemind").val().length==0){
				msAndroid.toast("设置提醒时间");
				return;
			}
			if($("#location").val().length==0){
				msAndroid.toast("设置上门地址");
				return;
			}
			//检查事前提醒
			var remindeDescr = $('#timeRemind').val();
			var remindeMinutes = 0;
			if(remindeDescr.indexOf("30分钟") != -1) {
				remindeMinutes = 30;
			}else if(remindeDescr.indexOf("1小时") != -1) {
				remindeMinutes = 60;
			}else if(remindeDescr.indexOf("2小时") != -1) {
				remindeMinutes = 120;
			}else if(remindeDescr.indexOf("4小时") != -1) {
	 		 	remindeMinutes = 240;
 		 	}
 		 	//预约到场时间
 		 	if(remindeMinutes > 0) {
 		 		var choosetime = $('#pendingtime').val();
	 		 	choosetime = choosetime.replace(/-/g,"/");
	 		 	choosetime = new Date(choosetime);
	 		 	choosetime.setTime(choosetime.getTime()-1000*remindeMinutes*60);
	 		 	if(choosetime < new Date()) {
	 		 		msAndroid.toast("提醒时间不能早于当前时间");
					return;
	 		 	}
			}
		}
		if($("#pendingcause").val().length==0){
			msAndroid.toast("填写改约原因");
			return;
		}
		var json=msAndroid.changedTicketVO("#form");
		json.action=$(this).attr("action");
		var url=$("#form").attr("action")+json.action;
		msAndroid.post(url,json,"put","active");
	});
 });
</script>
</html>